package com.foreknow.demo4;

public class Master {
//    public void cure(Pet pet) {
//        if (pet.getHealth() < 50) {
//            pet.toHospital();
//            System.out.println("吃药......");
//        }
//    }

    public void feed(Pet pet) {
        pet.eat();
    }

    public void play(Pet pet) {
        if (pet instanceof Dog)
            ((Dog) pet).run();
        else if (pet instanceof Penguin)
            ((Penguin) pet).swimming();
    }

    public static void main(String[] args) {
        Master master = new Master();
//        Dog dog = new Dog();
//        dog.setName("杨昊天");
//        dog.setLove(-100);
//        dog.setHealth(44);
//        master.cure(dog);
//
//        Penguin penguin = new Penguin();
//        penguin.setName("杨昊天");
//        penguin.setLove(-100);
//        penguin.setHealth(20);
//        master.cure(penguin);

        Pet p = new Dog();
        p.setName("qq");
        p.setLove(-100);
        p.setHealth(44);
        p.cure();
        master.feed(p);
        master.play(p);

        p = new Penguin();
        p.setName("aa");
        p.setLove(-100);
        p.setHealth(20);
        p.cure();
        master.feed(p);

        master.play(p);

    }
}
